﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TreeSharp;

namespace FelMaster.Classes.Warlock
{
    class Demonology_PetSwap : TalentBase
    {
        public override string Name
        {
            get { return "End gear Demonology with pet swap"; }
        }

        public override string KeySpell
        {
            get { return "Summon Felguard"; }
        }

        //I want to keep moving at melee range while morph is available
        //note that this info is used only if you enable moving/facing in the CC settings.
        public override float CombatMaxDistance
        {
            get
            {
                return (SC.CanCast("Metamorphosis") || SC.PlayerHasBuff("Metamorphosis")) ? 10f : 40f;
            }
        }

        //adding some help about cooldown management
        public override string Help
        {
            get
            {
                return "This rotation would fit any demonology specced locks running high level raids.\n" +
                    "Ensure you're at least at 10yards from your target to maximize your dps, even during burst phase if possible.\n"+
                    "If you're managing cooldowns by yourself, here's the burst level scaling:\n" +
                    "   1: Switch to felguard, demon soul, trinket and metamorphosis\n" +
                    "   2: Summon doomguard\n" +
                    "-----------------------------------------";
            }
        }

        public override Composite SingleRotation
        {
            get
            {
                return new Sequence(
                    //this is the burst phase pre-rotation. Called if and only if SC.BurstLevel > 0
                    SC.BurstSequence(
                        //make sure we got enough mana before bursting
                        SC.CastSpell("Life Tap", a => Me.ManaPercent < 50 && !SC.PlayerHasBuff("Metamorphosis"), "Life tap before burst - mana < 50%"),
                            
                        SC.CastUniqueSpell("Summon Felguard", a => SC.CanCast("Demon Soul") && SC.CanCast("Metamorphosis") && SC.CanCast("Devour Magic(Special Ability)"), "Summon Felguard"),
                        SC.CastBuff("Demon Soul", a => SC.TargetHasDebuff("Legion Strike"), "Demon Soul"),

                        //ensure we use moonwell chalice before meta if both are available
                        SC.UseTrinket(70142, a => SC.PlayerHasBuff("Demon Soul: Felguard") && SC.CanCast("Metamorphosis") && !SC.PlayerHasBuff("Blessing of the Moonwell"), "Trinket before meta: Moonwell Chalice"),
                    
                        //then cast meta according to moonwell chalice buff, if we have it
                        //it is very important to check for the moonwell buff before popping meta (see EJ post)
                        SC.CastBuff("Metamorphosis", a => SC.PlayerHasBuff("Demon Soul: Felguard") && (SC.PlayerHasBuff("Blessing of the Moonwell") || !SC.Trinkets.Contains(70142)), "Metamorphosis under Moonwell Chalice (burst this shit!)"),

                        SC.CastSpell("Felstorm(Special Ability)", a => true, "Felstorm(Special Ability)"),

                        //don't summon doomguard if moonwell chalice is not popped, if we have it
                        SC.CastSpell("Summon Doomguard", a => SC.BurstLevel > 1 && (SC.PlayerHasBuff("Blessing of the Moonwell") || (!SC.Trinkets.Contains(70142) || !SC.IsEquippedItemUsable(70142)) ), "Doomguard"),

                        SC.CastSpell("Soulburn", a => SC.PlayerHasBuff("Demon Soul: Felguard"), "Soulburn"),
                        SC.CastUniqueSpell("Summon Felhunter", a => SC.PlayerHasBuff("Soulburn"), "Soulburn Felhunter")
                    ),

                    //and here's our normal rotation, which is always called, even while bursting
                    new PrioritySelector(
                        //dont break hellfire with life tap
                        SC.CastSpell("Life Tap", a => Me.ManaPercent < 20 && !SC.PlayerIsChanneling, "Life tap - mana < 20%"),
                        SC.UseEngineerGloves(a => true, "Engineer's glove enchant"),

                        SC.CastSpell("Immolation Aura", a => SC.PlayerHasBuff("Metamorphosis") && SC.DistanceToTargetBoundingBox() <= 10f, "Immolation Aura"),
                        
                        //aoe stuff here.
                        SC.ChannelAreaSpell("Hellfire", 11.0, false, 4, 0.0, 0.0, a => true, "Hellfire"),

                        SC.CastDebuff("Curse of the Elements", a => true, "Curse Of The Elements"),
                        SC.CastDebuff("Immolate", a => true, "Immolate"),
                        SC.CastSpell("Hand of Gul'dan", a => true, "Hand of Gul'dan"),
                        SC.CastDebuff("Bane of Doom", a => true, "Bane of Doom"),
                        SC.CastDebuff("Corruption", a => true, "Corruption"),
                        SC.CastConicSpell("Shadowflame", 11f, 33f, a => true, "ShadowFlame"),
                        SC.CastSpell("Shadow Bolt", a => SC.PlayerHasBuff("Shadow Trance"), "Instant Shadow Bolt"),
                        SC.CastSpell("Incinerate", a => SC.PlayerHasBuff("Molten Core") && SC.TargetHasDebuff("Immolate") && SC.TargetHasDebuff("Corruption") && SC.TargetHasDebuff("Bane of Doom"), "Incinerate"),
                        SC.CastSpell("Soul Fire", a => SC.PlayerHasBuff("Decimation"), "Soul Fire"),
                        SC.CastSpell("Shadow Bolt", a => SC.TargetHasDebuff("Immolate") && SC.TargetHasDebuff("Corruption") && SC.TargetHasDebuff("Bane of Doom"), "Shadow Bolt"),
                        SC.CastSpell("Life Tap", a => Me.IsMoving && Me.HealthPercent > Me.ManaPercent && Me.ManaPercent < 80, "Life tap while moving"),
                        SC.CastSpell("Fel Flame", a => Me.IsMoving, "Fel flame while moving")
                    )
                );
            }
        }

        public override Composite Buffs
        {
            get
            {
                return new PrioritySelector(
                    //buffs
                    SC.CastBuff("Fel Armor", a => true, "Fel Armor"),
                    SC.CastUniqueSpell("Summon Felguard", a => !Me.Combat && !Me.Mounted && Pet == null || Pet.Dead, "Summon new Felguard"),
                    SC.CastBuff("Soul Link", a => Pet != null && Pet.IsAlive, "Soul Link")
                );
            }
        }

        public override Composite PVPRotation
        {
            get { throw new NotImplementedException(); }
        }

        public override Composite PVERotation
        {
            get
            {
                //I want to use the same PVE rotation as the solo one
                return SingleRotation;
            }
        }
    }
}
